// model/Showtime.java
package main.java.com.cinema.model;

import java.io.Serializable;
import java.time.LocalDateTime;

public class Showtime implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private String movieId;
    private String hallId;
    private LocalDateTime startTime;
    private double price;
    private boolean[][] seatStatus;

    public Showtime() {
        System.out.println("DEBUG: 创建空的Showtime对象");
    }

    public Showtime(String id, String movieId, String hallId, LocalDateTime startTime,
                    double price, int rows, int seatsPerRow) {
        System.out.println("DEBUG: 创建Showtime对象 - ID: " + id + ", movieId: " + movieId +
                ", hallId: " + hallId);
        this.id = id;
        this.movieId = movieId;
        this.hallId = hallId;
        this.startTime = startTime;
        this.price = price;
        this.seatStatus = new boolean[rows][seatsPerRow];
        System.out.println("DEBUG: Showtime对象创建完成，座位矩阵: " + rows + "×" + seatsPerRow);
    }

    // Getters and Setters
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }

    public String getMovieId() { return movieId; }
    public void setMovieId(String movieId) { this.movieId = movieId; }

    public String getHallId() { return hallId; }
    public void setHallId(String hallId) { this.hallId = hallId; }

    public LocalDateTime getStartTime() { return startTime; }
    public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }

    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }

    public boolean[][] getSeatStatus() { return seatStatus; }
    public void setSeatStatus(boolean[][] seatStatus) { this.seatStatus = seatStatus; }

    public boolean isSeatOccupied(int row, int seat) {
        if (row >= 0 && row < seatStatus.length && seat >= 0 && seat < seatStatus[row].length) {
            return seatStatus[row][seat];
        }
        return true;
    }

    public void setSeatOccupied(int row, int seat, boolean occupied) {
        if (row >= 0 && row < seatStatus.length && seat >= 0 && seat < seatStatus[row].length) {
            seatStatus[row][seat] = occupied;
        }
    }

    public int getTotalSeats() {
        int total = 0;
        for (boolean[] row : seatStatus) {
            total += row.length;
        }
        return total;
    }

    public int getAvailableSeats() {
        int available = 0;
        for (boolean[] row : seatStatus) {
            for (boolean seat : row) {
                if (!seat) {
                    available++;
                }
            }
        }
        return available;
    }
}
